package com.mobiletrain.org.motherkitch;

import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.mobiletrain.org.motherkitch.adapter.SplashAdapter;

import java.util.ArrayList;


public class GuideActivity extends ActionBarActivity implements ViewPager.OnPageChangeListener {

    private ArrayList<View> views;
    private ViewPager pager;
    private RadioGroup group;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        pager = (ViewPager) findViewById(R.id.pager);
        group = (RadioGroup) findViewById(R.id.splash_group);
        ((RadioButton) group.getChildAt(0)).setChecked(true);
        initViews();
        pager.setAdapter(new SplashAdapter(this, views));
        pager.setOnPageChangeListener(this);
    }

    public void initViews() {
        views = new ArrayList<View>();
        views.add(LayoutInflater.from(this).inflate(R.layout.wel1_item, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.wel2_item, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.wel3_item, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.wel4_item, null));
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_guide, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        ((RadioButton) group.getChildAt(position)).setChecked(true);

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
